package com.huidao.servlet.buyer;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Goods;
import com.huidao.service.buyer.GetGoodsService;
import com.huidao.service.buyer.GetGoodsServiceImpl;


/**
 * Servlet implementation class GetBuyerGoodsListServlet
 */
public class GetBuyerGoodsListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetBuyerGoodsListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String keyName = request.getParameter("keyName");	
		System.out.println(keyName);
		String gid =request.getParameter("id");
		long id = 0;
		if(gid!=null){
			id=Long.parseLong(gid);
		}
		int currentpage = 1;
		String curr = request.getParameter("currentpage");
		if(curr!=null){
			currentpage = Integer.parseInt(curr);
		}
		GetGoodsService gs = new GetGoodsServiceImpl();
		int totalpage = gs.getTotalPage(keyName, id);
		if(currentpage>totalpage){
			currentpage=totalpage;
		}
		System.out.println(currentpage);
		List<Goods> goodsList =gs.getGoodsList(keyName, currentpage, id);
		request.setAttribute("TotalPage", totalpage);
		request.setAttribute("CurrentPage", currentpage);
		request.setAttribute("goodsList", goodsList);
		request.setAttribute("id", gid);
		request.getRequestDispatcher("buyergoodslist.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
